package com.easylinkin.linkappapi.lobar.controller;

import com.easylinkin.linkappapi.lobar.dto.UserCertificateDTO;
import com.easylinkin.linkappapi.lobar.entity.UserCertificate;
import com.easylinkin.linkappapi.lobar.service.UserCertificateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: 资质证书管理
 */
@RestController
@RequestMapping("userCertificate")
@Api(tags = "资质证书管理")
public class UserCertificateController {

  @Autowired
  private UserCertificateService userCertificateService;

  /**
   * @Description: 增加资质证书
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping
  @ApiOperation("增加资质证书")
  public RestMessage insert(@RequestBody UserCertificate userCertificate){
    //todo 参数验证
    String userId = userCertificateService.insert(userCertificate);
    return RestBuilders.successBuilder().data(userId).build();
  }

  /**
   * @Description: 删除资质证书（包含批量删除）
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @DeleteMapping
  @ApiOperation("删除资质证书（包含批量删除）")
  public RestMessage delBatch(@RequestBody UserCertificate userCertificate){
    Assert.notEmpty(userCertificate.getIds(),"id不能为空");
    userCertificateService.removeByIds(userCertificate.getIds());
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 编辑资质证书
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PutMapping
  @ApiOperation("编辑资质证书")
  public RestMessage updateById(@RequestBody UserCertificate userCertificate){
    Assert.notNull(userCertificate.getId(),"id不能为空");
    userCertificateService.updateOne(userCertificate);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据id查询资质证书详情
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询资质证书详情")
  public RestMessage findById(@PathVariable("id")Long id) {
    Assert.notNull(id,"id不能为空");
    UserCertificate userCertificate = userCertificateService.getById(id);
    return RestBuilders.successBuilder().data(userCertificate).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件查询")
  public RestMessage queryList(@RequestBody UserCertificate userCertificate){
    List<UserCertificateDTO> record =  userCertificateService.queryList(userCertificate);
    return RestBuilders.successBuilder().data(record).build();
  }

  /**
   * @Description: 批量编辑用户id
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PutMapping("userId")
  @ApiOperation("批量编辑用户id")
  public RestMessage updateByUserId(@RequestBody UserCertificate userCertificate){
    userCertificateService.updateByUserId(userCertificate);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据用户id删除
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @DeleteMapping("userId")
  @ApiOperation("根据用户id删除")
  public RestMessage deleteByUserId(@RequestBody UserCertificate userCertificate){
    userCertificateService.deleteByUserId(userCertificate);
    return RestBuilders.successBuilder().build();
  }
}

